
exports.harvest = function(player, req, resp, onHandled) {
    player.action.score = 20;
    do{
        var user = player.user;

        var levelConf = gConfLevel[user.status.level]
        if( !levelConf ) {
            resp.code = 1; resp.desc = 'level error'; break;
        }

        var now = common.getTime();
        var passed =  now - user.castle.timer;
        if( passed <= 10 ) {
            resp.code = 1; resp.desc = 'time error'; break;
        }
        var addGold = +Math.floor(passed * (+levelConf.GoldPerHour) / 3600);
        if( addGold > +levelConf.GoldMax ) {
            addGold = +levelConf.GoldMax;
        }

        user.castle.timer = now; 
        user.status.gold += addGold;

        player.markDirty('castle.timer');
        player.markDirty('status.gold');

        player.doDailyTask(gConfDailyTask.HarvestCastle);
        player.doTask('HarvestGold','all');

        resp.data.gold = addGold;
        resp.data.timer = user.castle.timer;
        resp.daily_task = gConfDailyTask.HarvestCastle;

    }while(false);

    onHandled();
}
